package controllers;

import models.Admin;
import models.FoodCourt;
import models.Picture;
import models.Place;
import models.Telephone;
import models.User;
import play.data.Upload;
import play.mvc.Controller;
import play.mvc.With;
import util.FileUtil;

@With(Secure.class)
public class Court extends Controller {

	public static void blank() {
		render();
	}

	public static void create(FoodCourt foodCourt, Telephone telephone, Upload picture) {
		PlaceController.savePlace(foodCourt, telephone, picture);
		Admin user = Admin.find("from Admin u where u.email = ?", Security.connected()).first();
		user.getFoodCourts().add(foodCourt);
		user.save();
		list();
	}

	public static void list() {
		User user = User.find("from User u where u.email = ?", Security.connected()).first();
		session.put("userName", user.getName());
		render(user);
	}

	public static void stores(long id) {
		FoodCourt court = FoodCourt.findById(id);
		render(court);
	}

	public static void show(long id) {
		FoodCourt foodCourt = FoodCourt.findById(id);
		render(foodCourt);
	}

	public static void delete(long id) {
		FoodCourt foodCourt = FoodCourt.findById(id);
		foodCourt.setRemoved(true);
		foodCourt.save();
		list();
	}
	
	public static void save(FoodCourt foodCourt, Telephone telephone, Upload picture) {
		PlaceController.savePlace(foodCourt, telephone, picture);
		list();
	}
}
